<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			div{
				width: 200px;
				height: 200px;
				border: 1px black solid;
			}
			
			.background{
				background-color: red;
			}
			.whi{
				background-color: white;
			}
		</style>
	</head>
	<body>
		<div class="c1 whi"></div>
		<div class="c1 whi"></div>
		<div class="c1 whi"></div>
		<div class="c1 whi"></div>
		<div class="c1 whi"></div>
		<script>
			//获取五个div
			// var divs = document.getElementsByTagName("div");
			// var divs = document.getElementsByClassName("1");
			// var divs = document.querySelectorAll('div');
			 var divs = document.querySelectorAll(".c1")
			
			//对divs数组遍历
			for(let i=0;i<divs.length;i++){
				divs[i].addEventListener('click',fun1);
				
			}
			function fun1(){
				if(this.classList.contains("whi")){
					this.classList.remove("whi");
					this.classList.add("background");
				}else if(this.classList.contains("background")){
					this.classList.remove("background");
					this.classList.add("whi");
				}
				
			}
			
			/* for(var i=0;i<5;i++){
				var div = document.getElementsByTagName('div')[i];
				div.addEventListener('click',fun1);
				div.addEventListener('click',fun2);
				function fun1(){
					this.classList.remove("whi");
					this.classList.add("background");
				}
				function fun2(){
					this.classList.remove("background");
					this.classList.add("whi");
				}
			 } */
			他们刚才不是说去当保安吗,我想跟你说,欢迎业主回家!等我去你们小区
		</script>
	</body>
</html>